<template>
  <basic-container>
    <basic-header title="首页弹窗"/>
    <apply-table 
      ref="table"
      :action="action"
      :viewBtn="false"
      detail='/wel/popDetail'
    >
      <template slot="slot-body" slot-scope="{ row }">
        <span v-if="row.popupType === 'COUPON'" class="text-waring">
          {{ `满${row.fullMoney}减${row.discounts}` }}
        </span>
        <span v-else>{{ row.body }}</span>
      </template>
      <template 
        slot-scope="{ row }"
        slot="applyMenu"
      >
        <el-button 
          plain
          :type="row.isPutAway ? 'warning' : 'success'"
          size="small"
          :icon="`el-icon-${row.isPutAway ? 'download' : 'upload2'}`"
          @click.stop="handleChange(row)"
        >{{row.isPutAway ? '下架' : '上架'}}</el-button>
      </template>
    </apply-table>
  </basic-container>
</template>
<script>
import ApplyTable from '@/components/ApplyTable'
import actionTypes from '@/const/action'
import { PromisePopupPutAway } from '@/api/config';
export default {
  name: 'popup',
  components: { ApplyTable },
  data() {
    return {
      action: actionTypes.HOMEPAGE_POPUP
    }
  },
  methods: {
    handleChange(row) {
      const type = row.isPutAway ? '下架' : '上架'
      this.$confirm(`确认${type}吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        PromisePopupPutAway(row.id, !row.isPutAway, row.popupType).then(() => {
          this.$message({
            type: 'success',
            message: `已成功${type}`
          })
          this.$refs.table.RefreshData()
        }).catch(error => {
          console.log('error')
          this.$message({
            type: 'error',
            message: error
          })
        })
      })
    },
  }
}
</script>

